<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model common\models\FrontUser */

$this->title = $model->username;
$this->params['breadcrumbs'][] = ['label' => '经销商管理', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$per_url = Yii::$app->params['front_imgurl'];
?>
<div class="front-user-view">

    <p>
        <?= Html::a('编辑', ['update', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
        <?= Html::a('删除', ['delete', 'id' => $model->id], [
            'class' => 'btn btn-danger',
            'data' => [
                'confirm' => 'Are you sure you want to delete this item?',
                'method' => 'post',
            ],
        ]) ?>
        <?= Html::a('重置密码', ['reset-password', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
        <?= Html::a('上传电子版品牌授权证书', ['upload', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
        <?= Html::a('相关产品添加', ['/home/customer/create', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
    </p>
    <div class="row">
        <div class="col-md-6">
            <div class="panel panel-info">
                <div class="panel-heading">详情</div>
                <?= DetailView::widget([
                    'model' => $model,
                    'attributes' => [
                        'id',
                        [
                            'label' => '用户名',
                            'format' => 'raw',
                            'attribute' => 'username',
                            'value' => function($model) {
                                return $model->username;
                            },
                        ],
                        [
                            'label' => '公司名称',
                            'format' => 'raw',
                            'attribute' => 'company_name',
                            'value' => function($model) {
                                return $model->company_name;
                            },
                        ],
                        // 'auth_key',
                        // 'password_hash',
                        // 'password_reset_token',
                        'email:email',
                        [
                            'label' => '状态',
                            'format' => 'raw',
                            'attribute' => 'status',
                            'value' => function($model) {
                                if($model->status == 10){
                                    return '<span class="btn btn-success btn-xs">可用</span>';
                                }else{
                                    return '<span class="btn btn-danger btn-xs">不可用</span>';
                                }
                            },
                        ],
                        [
                            'label' => '创建时间',
                            'format' => 'raw',
                            'attribute' => 'created_at',
                            'value' => function($model) {
                                return date('Y-m-d H:i',$model->created_at);
                            },
                        ],
                        [
                            'label' => '更新时间',
                            'format' => 'raw',
                            'attribute' => 'updated_at',
                            'value' => function($model) {
                                return date('Y-m-d H:i',$model->updated_at);
                            },
                        ],
                    ],
                ]) ?>
            </div>
        </div>
        <div class="col-md-6">
            <div class="panel panel-info">
                <div class="panel-heading">授权文件</div>
                <?php if( !empty($file_model['path']) ){ ?>
                <iframe src="<?=$per_url . $file_model['path']?>" frameborder="0" scrolling="no" id="external-frame" onload="setIframeHeight(this)" style="width: 100%;height: 260px"></iframe>
                <?php }?>
            </div>
        </div>
        <div class="col-md-12">
            <div class="panel panel-info">
                <div class="panel-heading">授权产品</div>
                <table class="table table-hover">
                        <tr>
                            <th width="120px">操作</th>
                            <th width="120px">序号</th>
                            <th>产品型号</th>
                            <th>价格（含税运）</th>
                            <th>货期</th>
                            <th>起订量</th>
                            <th>备注</th>
                            <th>创建时间</th>
                        </tr>
                        <?php foreach(\common\components\Tools::getCustomerProduct($model->id) as $k=>$v){?>
                            <tr>
                                <td>
                                    <a class="btn btn-info btn-xs" href="/home/customer/update?id=<?=$v['id']?>" title="编辑"><span class="glyphicon glyphicon-edit"></span></a>
                                    <?= Html::a('<span class="glyphicon glyphicon-trash"></span>', ['/home/customer/delete', 'id' => $v['id']], [
                                        'class' => 'btn btn-danger btn-xs',
                                        'data' => [
                                            'confirm' => 'Are you sure you want to delete this item?',
                                            'method' => 'post',
                                        ],
                                    ]) ?>
                                </td>
                                <td><?=$k + 1?></td>
                                <td><?=$v['product_code']?></td>
                                <td><?=$v['price']?></td>
                                <td><?=$v['product_date']?></td>
                                <td><?=$v['product_num']?></td>
                                <td><?=$v['remark']?></td>
                                <td><?=date('Y-m-d H:i',$v['create_at'])?></td>
                            </tr>
                        <?php }?>
                    </table>
            </div>
        </div>
    </div>
    

</div>
